//
//  XHMyTemplateManager.m
//  huimei
//
//  Created by 冷山 on 16/1/27.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

static NSString *TemplateSequenceNBR = @"KeyShopCartProductArray";


#import "XHMyTemplateManager.h"

@interface XHMyTemplateManager()

@end

@implementation XHMyTemplateManager

///修改一个自定义模板
+ (void)editTemlpate:(NSDictionary *)dic sequenceNBR:(NSString*)sequenceNBR
{
    NSString * key = [NSString stringWithFormat:@"%@",sequenceNBR];
    NSString * uuid = dic[@"UUID"];
    NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults];
    NSMutableArray * mutableArray = [[userDefaluts objectForKey:key] mutableCopy];

    for (int i = 0; i < mutableArray.count;i++)
    {
        NSMutableDictionary * mutableDic = mutableArray[i];
        if ([mutableDic[@"UUID"] isEqualToString:uuid])
        {
            [mutableArray removeObject:mutableDic];
            [mutableArray addObject:dic];
        }
    }
    [self userDefaultsWithArray:mutableArray sequenceNBR:key];
    
}

///保存成功提现的信息 
+ (void)addTemlpate:(NSDictionary *)dic sequenceNBR:(NSString *)sequenceNBR 
{
    NSString * key = [NSString stringWithFormat:@"%@",sequenceNBR];
    NSUserDefaults * userDefaluts = [NSUserDefaults standardUserDefaults];
    NSMutableArray * mutableArray = [[userDefaluts objectForKey:key] mutableCopy];
    if (!mutableArray)
    {
        NSMutableArray * mutableArray = [[NSMutableArray alloc]init];
        [mutableArray addObject:dic];
        [self userDefaultsWithArray:mutableArray sequenceNBR:key];
    }
    else
    {
        [mutableArray removeAllObjects];
        [mutableArray addObject:dic];
        [self userDefaultsWithArray:mutableArray sequenceNBR:key];
    }
}

///使用UseDefaults本地存储模板库
+ (void)userDefaultsWithArray:(NSMutableArray *)mutableArray sequenceNBR:(NSString *)sequenceNBR
{
    if (mutableArray.count == 0)
    {
//        [PromptAction showErrorPrompt:@"保存失败"];
    }
    else
    {
//        [PromptAction showSuccessPrompt:@"保存成功"];
    }
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:mutableArray forKey:sequenceNBR];
}

@end
